package com.myapplication.ui.homefragment.shopfragment.activity_banner.activity_banner1;


import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.myapplication.R;
import com.myapplication.bean.DeatilBanner1;

import java.util.List;


/**
 * Created by zitaojiang on 2016/10/18.
 */
public class MyBannerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<DeatilBanner1.RowsBean> mList;

    public MyBannerAdapter(List<DeatilBanner1.RowsBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(context).inflate(R.layout.cardview_item,parent,false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if(mList.get(position).getOldPrice().length()>3){
            ((MyViewHolder) holder).tv_old_price.setText("零售价:"+"¥"+mList.get(position).getOldPrice().substring(0,4));

        }else {
            ((MyViewHolder) holder).tv_old_price.setText("零售价:"+"¥"+mList.get(position).getOldPrice());
        }
        ((MyViewHolder) holder).tv_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        if (mList.get(position).getNewPrice().length()>3){
            ((MyViewHolder) holder).tv_new_price.setText("秒杀价:"+"¥"+mList.get(position).getNewPrice().substring(0,4));
        }else {
            ((MyViewHolder) holder).tv_new_price.setText("秒杀价:"+"¥"+mList.get(position).getNewPrice());
        }

        ((MyViewHolder) holder).tv_collapsing_item.setText(mList.get(position).getName());

        Glide.with(context).load(mList.get(position).getProductImg()).into(((MyViewHolder) holder).iv_collapsing_item);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_collapsing_item,tv_new_price,tv_old_price;
        private ImageView iv_collapsing_item;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_collapsing_item = (TextView) itemView.findViewById(R.id.tv_collapsing_item);
            tv_new_price = (TextView) itemView.findViewById(R.id.tv_new_price);
            tv_old_price = (TextView) itemView.findViewById(R.id.tv_old_price);
            iv_collapsing_item = (ImageView) itemView.findViewById(R.id.iv_collapsing_item);

        }
    }

}
